﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DBModel
{
    public partial class Education
    {
        public override string ToString()
        {
            return string.Format("{0}, {1}, {2}, {3} -> {4} ", EducationId, EducationName, SiteOfEducation,
                StartDate.ToShortDateString(), EndDate.ToShortDateString());
        }
        public string ToHtml()
        {
            return string.Format("{0} &ndash; {1}<br /> {2}<br /> {3}<br />{4}<br />",
                StartDate.ToShortDateString(), EndDate.ToShortDateString(),
                EducationName, SiteOfEducation, EducationDescription);
        }
    }

    public static class EducationDB
    {
        public static Education GetEducationById(int id)
        {
            return DB.Context.Educations
                .Where(e => e.EducationId == id)
                .SingleOrDefault(e => e.IsDeleted == false);
        }

        public static bool DeleteEducationById(int id)
        {
            Education educationToDelete = GetEducationById(id);
            if (educationToDelete != null)
            {
                educationToDelete.IsDeleted = true;
                int affectedRows = DB.Context.SaveChanges();
                return (affectedRows > 0);
            }
            return false;
        }
    }
}
